#ifndef FPLAYER_FFMPEGCAPTURE_H
#define FPLAYER_FFMPEGCAPTURE_H

#include "Capture.h"
#include "Codec.h"
#include "ResampleWrapper.h"

/**
 * author: x-fan
 * date: 2024/1/9
 * desc: FFMpeg解复用
 */
class FFMpegCapture : public ICapture, public IDecodeCallback {
private:
  //解封装格式上下文
  AVFormatContext *_pFormatCtx = nullptr;
  AVPacket *_pPacket = nullptr;

  //视频解码器
  IDecoder *_pVDecoder = nullptr;
  DecoderParam _VParam;

  //音频解码器
  IDecoder *_pADecoder = nullptr;
  DecoderParam _AParam;

  //音频重采样
  ResampleWrapper _Resample;

protected:
  /**
   * 打开输入(MP4,RTMP,RTSP)
   * @param ppFormatCtx 封装格式上下文
   * @param pDevice 采集设备
   * @return 0 is Success
   */
  virtual int32_t openInput(AVFormatContext **ppFormatCtx, IPCameraDevice *pDevice) = 0;

  /**
   * 关闭输入
   * @param ppFormatCtx 封装格式上下文
   */
  virtual void closeInput(AVFormatContext **ppFormatCtx) = 0;

public:
  explicit FFMpegCapture(IPCameraDevice *pCapDev);

  virtual ~FFMpegCapture() noexcept;

  void startCapture() override;

  void stopCapture() override;

  int32_t capacity() override;

  void onDecodeData(IDecoder *pDecoder, AVFrame *pFrame) override;
};


#endif //FPLAYER_FFMPEGCAPTURE_H
